﻿
Imports cerveza
Public Class ProductosForm

    Private Sub btnBuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBuscar.Click
        Dim criterio As String = Me.txtBuscar.Text
        'MsgBox(criterio)

        Dim negocio As New ProductoNegocio
        Dim categorias As Collection = negocio.buscarPorNombre(criterio)
        Me.dgvCategorias.DataSource = categorias
        Me.dgvCategorias.EditMode = False

        Me.dgvCategorias.Columns(0).HeaderText = "idproducto"
        Me.dgvCategorias.Columns(1).HeaderText = "nombre"
        Me.dgvCategorias.Columns(2).HeaderText = "descripcion"
        Me.dgvCategorias.Columns(3).HeaderText = "costo"
        Me.dgvCategorias.Columns(4).HeaderText = "fecha"
        Me.dgvCategorias.Columns(5).HeaderText = "stock"

    End Sub

    Private Sub ProductosForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        With Me.dgvCategorias.ColumnHeadersDefaultCellStyle
            .BackColor = Color.Red
            .ForeColor = Color.White
        End With

    End Sub



    Private Sub btnEditar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEditar.Click
        Dim seleccionado = Me.dgvCategorias.CurrentRow.Cells(0).Value.ToString
        Dim form As New ProductoNuevoForm
        form.MdiParent = Me.MdiParent
        form.lblId.Text = seleccionado
        form.productosForm = Me
        form.Show()
    
    End Sub

    Private Sub btnEliminar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEliminar.Click
        Dim seleccionado = Me.dgvCategorias.CurrentRow.Cells(0).Value.ToString
        Dim negocio As New ProductoNegocio
        negocio.eliminar(seleccionado)
        dgvCategorias.DataSource = ""
        MsgBox("Producto eliminado!")
    End Sub

    Private Sub btnNuevo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNuevo.Click
        Dim form As New ProductoNuevoForm
        form.MdiParent = Me.MdiParent
        form.productosForm = Me
        form.Show()
    End Sub
End Class